<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Anderoid基础," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="自定义对话框123456789private void showDialog() &amp;#123;    AlertDialog.Builder builder = new AlertDialog.Builder(Blackname_Activity.this);    //要自定义对话框的样式所以调用creat方法    AlertDialog dialog = builder.create();">
<meta name="keywords" content="Anderoid基础">
<meta property="og:type" content="article">
<meta property="og:title" content="Android基础（一）">
<meta property="og:url" content="http://yoursite.com/2016/11/30/Android基础（一）/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="自定义对话框123456789private void showDialog() &amp;#123;    AlertDialog.Builder builder = new AlertDialog.Builder(Blackname_Activity.this);    //要自定义对话框的样式所以调用creat方法    AlertDialog dialog = builder.create();">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2016-11-30T10:02:13.526Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android基础（一）">
<meta name="twitter:description" content="自定义对话框123456789private void showDialog() &amp;#123;    AlertDialog.Builder builder = new AlertDialog.Builder(Blackname_Activity.this);    //要自定义对话框的样式所以调用creat方法    AlertDialog dialog = builder.create();">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2016/11/30/Android基础（一）/"/>





  <title> Android基础（一） | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2016/11/30/Android基础（一）/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Android基础（一）
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-11-30T12:36:09+08:00">
                2016-11-30
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8BDD;&#x6846;"><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8BDD;&#x6846;" class="headerlink" title="&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8BDD;&#x6846;"></a>&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8BDD;&#x6846;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">showDialog</span><span class="params">()</span> </span>{</span><br><span class="line">    AlertDialog.Builder builder = <span class="keyword">new</span> AlertDialog.Builder(Blackname_Activity.<span class="keyword">this</span>);</span><br><span class="line">    <span class="comment">//&#x8981;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8BDD;&#x6846;&#x7684;&#x6837;&#x5F0F;&#x6240;&#x4EE5;&#x8C03;&#x7528;creat&#x65B9;&#x6CD5;</span></span><br><span class="line">    AlertDialog dialog = builder.create();</span><br><span class="line">    View view = View.inflate(getApplicationContext(), R.layout.blackname_insert_dialog, <span class="keyword">null</span>);</span><br><span class="line">    <span class="comment">//&#x5C06;&#x4F4E;&#x7248;&#x672C;&#x7684;&#x95F4;&#x8DDD;&#x53D6;&#x6D88;&#x6389;</span></span><br><span class="line">    dialog.setView(view,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">    dialog.show();</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="ListView&#x7684;&#x4F18;&#x5316;"><a href="#ListView&#x7684;&#x4F18;&#x5316;" class="headerlink" title="ListView&#x7684;&#x4F18;&#x5316;"></a>ListView&#x7684;&#x4F18;&#x5316;</h2><h3 id="ConvertView&#x7684;&#x590D;&#x7528;"><a href="#ConvertView&#x7684;&#x590D;&#x7528;" class="headerlink" title="ConvertView&#x7684;&#x590D;&#x7528;"></a>ConvertView&#x7684;&#x590D;&#x7528;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"> <span class="keyword">if</span> (view==<span class="keyword">null</span>){</span><br><span class="line">     <span class="comment">//&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6761;&#x76EE;&#x6240;&#x5BF9;&#x5E94;&#x7684;View&#x5BF9;&#x8C61; (&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x662F;&#x5426;&#x8981;&#x6302;&#x5728;&#x5230;&#x7236;&#x63A7;&#x4EF6;&#x4E0A; ,</span></span><br><span class="line">	&#x4E00;&#x822C;&#x4F20;&#x5165;<span class="keyword">null</span>)</span><br><span class="line">     view = View.inflate(Blackname_Activity.<span class="keyword">this</span>, R.layout.listview_blackname, <span class="keyword">null</span>);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="findViewById&#x7684;&#x590D;&#x7528;-ViewHolder&#x7684;&#x4F7F;&#x7528;"><a href="#findViewById&#x7684;&#x590D;&#x7528;-ViewHolder&#x7684;&#x4F7F;&#x7528;" class="headerlink" title="findViewById&#x7684;&#x590D;&#x7528; ViewHolder&#x7684;&#x4F7F;&#x7528;"></a>findViewById&#x7684;&#x590D;&#x7528; ViewHolder&#x7684;&#x4F7F;&#x7528;</h3><a id="more"></a>
<p>1,&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x7684;ViewHolder&#x5BF9;&#x8C61;&#xFF0C;&#x7C7B;&#x91CC;&#x9762;&#x521B;&#x5EFA;&#x6BCF;&#x4E2A;ListView&#x6761;&#x76EE;&#x4E2D;&#x7684;&#x63A7;&#x4EF6;&#x7684;&#x540D;&#x79F0;<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">ViewHolder</span></span>{</span><br><span class="line">    TextView tv_listView_blackname_phone;</span><br><span class="line">    TextView tv_listView_blackname_mode;</span><br><span class="line">    ImageView iv_blackname_del;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<p>2,&#x751F;&#x6210;ViewHolder&#x5BF9;&#x8C61;<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ViewHolder viewHolder = <span class="keyword">new</span> ViewHolder();</span><br></pre></td></tr></table></figure></p>
<p>&#x5B8C;&#x6574;&#x7248;<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">    listView&#x4F18;&#x5316;</span><br><span class="line">        <span class="number">1</span>:&#x590D;&#x7528;convertView</span><br><span class="line">        <span class="number">2</span>:&#x590D;&#x7528;ViewHolder&#x8BA9;&#x5176;&#x51CF;&#x5C11;findViewById()&#x6B21;&#x6570;</span><br><span class="line">        <span class="number">3</span>:<span class="keyword">static</span> ViewHolder</span><br><span class="line">        <span class="number">4</span>:&#x5206;&#x9875;&#x7B97;&#x6CD5;</span><br><span class="line"></span><br><span class="line">&#x6A21;&#x7248;&#x4EE3;&#x7801;</span><br><span class="line">          ViewHolder  viewHolder = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">if</span>(convertView == <span class="keyword">null</span>){</span><br><span class="line">        viewHolder = <span class="keyword">new</span> ViewHolder();</span><br><span class="line">        convertView = View.inflate();</span><br><span class="line">        viewHolder.text1 = convertView.findViewById(R.id.text1);</span><br><span class="line">        convertView.setTag(viewHolder);</span><br><span class="line">    }<span class="keyword">else</span>{</span><br><span class="line">        viewHolder = (ViewHolder)convertView.getTag();</span><br><span class="line">    }</span><br><span class="line">    viewHolder.text1.setText(<span class="string">&quot;&#x6587;&#x672C;&#x5185;&#x5BB9;&quot;</span>);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">ViewHolder</span></span>{</span><br><span class="line">        TextView text1;</span><br><span class="line">    }</span><br></pre></td></tr></table></figure></p>
<h2 id="&#x5C06;&#x6D41;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;"><a href="#&#x5C06;&#x6D41;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;" class="headerlink" title="&#x5C06;&#x6D41;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;"></a>&#x5C06;&#x6D41;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">  <span class="comment">//&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x662F;&#x5C06;&#x6D41;&#x7C7B;&#x578B;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x5BF9;&#x8C61;</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StreamUtil</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="comment">//&#x524D;&#x9762;&#x7C7B;&#x7684;&#x4E34;&#x65F6;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x5F0F;&#x4F20;&#x8FDB;&#x6765;</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> String <span class="title">streamToString</span><span class="params">(InputStream is)</span> </span>{</span><br><span class="line">        <span class="comment">//1,&#x5728;&#x8BFB;&#x53D6;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;,&#x5C06;&#x8BFB;&#x53D6;&#x7684;&#x5185;&#x5BB9;&#x5B58;&#x50A8;&#x503C;&#x7F13;&#x5B58;&#x4E2D;,&#x7136;&#x540E;&#x4E00;&#x6B21;&#x6027;&#x7684;&#x8F6C;&#x6362;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#x8FD4;&#x56DE;</span></span><br><span class="line">        ByteArrayOutputStream bos = <span class="keyword">new</span> ByteArrayOutputStream();</span><br><span class="line">        <span class="comment">//2,&#x8BFB;&#x6D41;&#x64CD;&#x4F5C;,&#x8BFB;&#x5230;&#x6CA1;&#x6709;&#x4E3A;&#x6B62;(&#x5FAA;&#x73AF;)</span></span><br><span class="line">        <span class="keyword">byte</span>[] buffer = <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">1024</span>];</span><br><span class="line">        <span class="comment">//3,&#x8BB0;&#x5F55;&#x8BFB;&#x53D6;&#x5185;&#x5BB9;&#x7684;&#x4E34;&#x65F6;&#x53D8;&#x91CF;</span></span><br><span class="line">        <span class="keyword">int</span> temp = -<span class="number">1</span>;</span><br><span class="line">        <span class="keyword">try</span> {</span><br><span class="line">            <span class="keyword">while</span>((temp = is.read(buffer))!=-<span class="number">1</span>){</span><br><span class="line">                bos.write(buffer, <span class="number">0</span>, temp);</span><br><span class="line">            }</span><br><span class="line">            <span class="comment">//&#x8FD4;&#x56DE;&#x8BFB;&#x53D6;&#x6570;&#x636E;</span></span><br><span class="line">            <span class="keyword">return</span> bos.toString();</span><br><span class="line">        } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        }<span class="keyword">finally</span>{</span><br><span class="line">            <span class="keyword">try</span> {</span><br><span class="line">                is.close();</span><br><span class="line">                bos.close();</span><br><span class="line">            } <span class="keyword">catch</span> (IOException e) {</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="&#x670D;&#x52A1;&#x7AEF;JSON&#x5199;&#x6CD5;"><a href="#&#x670D;&#x52A1;&#x7AEF;JSON&#x5199;&#x6CD5;" class="headerlink" title="&#x670D;&#x52A1;&#x7AEF;JSON&#x5199;&#x6CD5;"></a>&#x670D;&#x52A1;&#x7AEF;JSON&#x5199;&#x6CD5;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line">   <span class="string">&quot;version_name&quot;</span>: <span class="string">&quot;2.0&quot;</span>,</span><br><span class="line">   <span class="string">&quot;version_code&quot;</span>: <span class="number">2</span>,</span><br><span class="line">   <span class="string">&quot;description&quot;</span>: <span class="string">&quot;&#x6700;&#x65B0;&#x7248;&#x624B;&#x673A;&#x536B;&#x58EB;,&#x5FEB;&#x6765;&#x4E0B;&#x8F7D;&#x4F53;&#x9A8C;&#x5427;!&quot;</span>,</span><br><span class="line">   <span class="string">&quot;download_url&quot;</span>: <span class="string">&quot;http://10.0.2.2:8080/mobilesafe2.0.apk&quot;</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="JSON&#x89E3;&#x6790;&#xFF08;&#x4E0D;&#x9002;&#x7528;Gson&#xFF09;"><a href="#JSON&#x89E3;&#x6790;&#xFF08;&#x4E0D;&#x9002;&#x7528;Gson&#xFF09;" class="headerlink" title="JSON&#x89E3;&#x6790;&#xFF08;&#x4E0D;&#x9002;&#x7528;Gson&#xFF09;"></a>JSON&#x89E3;&#x6790;&#xFF08;&#x4E0D;&#x9002;&#x7528;Gson&#xFF09;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">        <span class="comment">//1&#xFF1A;&#x5C01;&#x88C5;URL&#x5730;&#x5740;</span></span><br><span class="line">        URL url= <span class="keyword">new</span> URL(<span class="string">&quot;http://192.168.1.101:8080/update.json&quot;</span>);</span><br><span class="line">        <span class="comment">//2:&#x5F00;&#x542F;&#x94FE;&#x63A5;</span></span><br><span class="line">        HttpURLConnection connection = (HttpURLConnection) url.openConnection();</span><br><span class="line">        <span class="comment">//3:&#x8BBE;&#x7F6E;&#x5E38;&#x89C1;&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF08;&#x8BF7;&#x6C42;&#x5934;&#xFF09;</span></span><br><span class="line">        connection.setConnectTimeout(<span class="number">3000</span>);<span class="comment">//&#x8FD9;&#x4E2A;&#x662F;&#x8BF7;&#x6C42;&#x8D85;&#x65F6;</span></span><br><span class="line">        connection.setReadTimeout(<span class="number">3000</span>);<span class="comment">//&#x8FD9;&#x4E2A;&#x662F;&#x8BFB;&#x53D6;&#x8D85;&#x65F6;  &#x610F;&#x601D;&#x662F;&#x548C; &#x670D;&#x52A1;&#x5668;&#x8FDE;&#x4E0A;&#x4E86;&#xFF0C;&#x4F46;&#x4E0D;&#x80FD;&#x8BFB;&#x53D6;&#x6570;&#x636E;</span></span><br><span class="line">        connection.setRequestMethod(<span class="string">&quot;POST&quot;</span>);<span class="comment">//&#x8FD9;&#x91CC;&#x662F;&#x8BBE;&#x7F6E;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;  GET&#x6216;&#x8005;POST   &#x9ED8;&#x8BA4;&#x5C31;&#x662F;GET&#x8BF7;&#x6C42;&#x5982;&#x679C;&#x4F60;&#x662F;GET&#x8BF7;&#x6C42;&#x53EF;&#x4EE5;&#x4E0D;&#x5199;</span></span><br><span class="line">        <span class="keyword">int</span> Code =  connection.getResponseCode();<span class="comment">//&#x83B7;&#x53D6;&#x8BF7;&#x6C42;&#x7801;</span></span><br><span class="line">        System.out.println(<span class="string">&quot;--------------------------------------&quot;</span>+Code);</span><br><span class="line">        <span class="keyword">if</span>(Code==<span class="number">200</span>){</span><br><span class="line">            <span class="comment">//&#x4EE5;&#x6D41;&#x7684;&#x5F62;&#x5F0F;&#x5C06;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x4E0B;&#x6765;</span></span><br><span class="line">            InputStream is = connection.getInputStream();</span><br><span class="line">            <span class="comment">//&#x5C06;&#x6D41;&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x56E0;&#x4E3A;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x5F88;&#x5E38;&#x7528;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x5C01;&#x88C5;&#x8D77;&#x6765;</span></span><br><span class="line">            String json = StreamUtil.streamToString(is);</span><br><span class="line">            Log.d(<span class="string">&quot;json&quot;</span>,json);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//&#x4E0B;&#x9762;&#x8FDB;&#x884C;JSON&#x7684;&#x89E3;&#x6790;</span></span><br><span class="line">            JSONObject jsonObject = <span class="keyword">new</span> JSONObject(json);</span><br><span class="line">            downloadUrl = jsonObject.getString(<span class="string">&quot;downloadUrl&quot;</span>);</span><br><span class="line">            String versionCode = jsonObject.getString(<span class="string">&quot;versionCode&quot;</span>);</span><br><span class="line">            String versionName = jsonObject.getString(<span class="string">&quot;versionName&quot;</span>);</span><br><span class="line">            versopmDes = jsonObject.getString(<span class="string">&quot;versopmDes&quot;</span>);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//&#x4E0B;&#x9762;&#x662F;&#x6D4B;&#x8BD5;&#x662F;&#x5426;&#x6B63;&#x5E38;&#x89E3;&#x6790;JSON</span></span><br><span class="line">            Log.d(<span class="string">&quot;json&quot;</span>,downloadUrl);</span><br><span class="line">            Log.d(<span class="string">&quot;json&quot;</span>,versionCode);</span><br><span class="line">            Log.d(<span class="string">&quot;json&quot;</span>,versionName);</span><br><span class="line">            Log.d(<span class="string">&quot;json&quot;</span>,versopmDes);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x6BD4;&#x672C;&#x5730;&#x7684;&#x7248;&#x672C;&#x9AD8;&#x5219;&#x63D0;&#x793A;&#x7528;&#x6237;&#x66F4;&#x65B0;</span></span><br><span class="line">            <span class="keyword">if</span> (mLocalVersioncode&lt;Integer.parseInt(versionCode)){</span><br><span class="line">                <span class="comment">//&#x63D0;&#x793A;&#x7528;&#x6237;&#x66F4;&#x65B0;</span></span><br><span class="line">                msg.what=UPDATE_VERSION;</span><br><span class="line">            }<span class="keyword">else</span> {</span><br><span class="line">                <span class="comment">//&#x5426;&#x5219;&#x76F4;&#x63A5;&#x8FDB;&#x5165;HOME&#x754C;&#x9762;</span></span><br><span class="line">                msg.what=ENTER_HOME;</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    } <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">        System.out.println(<span class="string">&quot;&#x8FDB;&#x5165;&#x4E86;CATH&quot;</span>+e);</span><br><span class="line">        <span class="comment">//&#x53D1;&#x751F;&#x5F02;&#x5E38;</span></span><br><span class="line">        msg.what = EXCEPTION;</span><br><span class="line">    }<span class="keyword">finally</span> {</span><br><span class="line">        <span class="keyword">long</span> Endm = System.currentTimeMillis();</span><br><span class="line">        <span class="keyword">try</span> {</span><br><span class="line">            Thread.sleep(<span class="number">3000</span>);</span><br><span class="line">        } <span class="keyword">catch</span> (InterruptedException e) {</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        }</span><br><span class="line">        mHandler.sendMessage(msg);</span><br><span class="line">    }</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h2 id="&#x4F7F;&#x7528;&#x5F00;&#x6E90;&#x6846;&#x67B6;Xutils&#x4E0B;&#x8F7D;"><a href="#&#x4F7F;&#x7528;&#x5F00;&#x6E90;&#x6846;&#x67B6;Xutils&#x4E0B;&#x8F7D;" class="headerlink" title="&#x4F7F;&#x7528;&#x5F00;&#x6E90;&#x6846;&#x67B6;Xutils&#x4E0B;&#x8F7D;"></a>&#x4F7F;&#x7528;&#x5F00;&#x6E90;&#x6846;&#x67B6;Xutils&#x4E0B;&#x8F7D;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">HttpUtils httpUtils = <span class="keyword">new</span> HttpUtils();</span><br><span class="line">            <span class="comment">//&#x53D1;&#x9001;&#x8BF7;&#x6C42;,&#x4F20;&#x9012;&#x53C2;&#x6570;(&#x4E0B;&#x8F7D;&#x5730;&#x5740;,&#x4E0B;&#x8F7D;&#x5E94;&#x7528;&#x653E;&#x7F6E;&#x4F4D;&#x7F6E;)</span></span><br><span class="line">            httpUtils.download(downloadUrl,Path,<span class="keyword">new</span> RequestCallBack&lt;File&gt;() {</span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onSuccess</span><span class="params">(ResponseInfo&lt;File&gt; fileResponseInfo)</span> </span>{</span><br><span class="line">                    <span class="comment">//&#x4E0B;&#x8F7D;&#x6210;&#x529F;&#x6267;&#x884C;&#x7684;&#x65B9;&#x6CD5;</span></span><br><span class="line">                    File apk = fileResponseInfo.result;</span><br><span class="line">                    <span class="comment">//&#x73B0;&#x5728;&#x5F00;&#x59CB;&#x5B89;&#x88C5;</span></span><br><span class="line">                    install(apk);</span><br><span class="line">                }</span><br><span class="line"></span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onFailure</span><span class="params">(HttpException e, String s)</span> </span>{</span><br><span class="line">                    <span class="comment">//&#x4E0B;&#x8F7D;&#x5931;&#x8D25;&#x6267;&#x884C;&#x7684;&#x65B9;&#x6CD5;</span></span><br><span class="line">                    Toast.makeText(Splash.<span class="keyword">this</span>,<span class="string">&quot;&#x8BF7;&#x68C0;&#x67E5;&#x7F51;&#x7EDC;&#x8BBE;&#x7F6E;&quot;</span>,Toast.LENGTH_SHORT).show();</span><br><span class="line">                }</span><br><span class="line"></span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onStart</span><span class="params">()</span> </span>{</span><br><span class="line">                    <span class="comment">//&#x5F00;&#x59CB;&#x4E0B;&#x8F7D;&#x6267;&#x884C;&#x7684;&#x65B9;&#x6CD5;</span></span><br><span class="line">                    Toast.makeText(Splash.<span class="keyword">this</span>,<span class="string">&quot;&#x5F00;&#x59CB;&#x4E0B;&#x8F7D;&quot;</span>,Toast.LENGTH_SHORT).show();</span><br><span class="line">                    <span class="keyword">super</span>.onStart();</span><br><span class="line">                }</span><br><span class="line"></span><br><span class="line">                <span class="meta">@Override</span></span><br><span class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onLoading</span><span class="params">(<span class="keyword">long</span> total, <span class="keyword">long</span> current, <span class="keyword">boolean</span> isUploading)</span> </span>{</span><br><span class="line">                    <span class="comment">//&#x4E0B;&#x8F7D;&#x8FC7;&#x7A0B;&#x4E2D;&#x6267;&#x884C;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x4EE5;&#x540E;&#x53EF;&#x4EE5;&#x653E;&#x4E0B;&#x8F7D;&#x7684;&#x8FDB;&#x5EA6;</span></span><br><span class="line">                    <span class="keyword">super</span>.onLoading(total, current, isUploading);</span><br><span class="line">                }</span><br></pre></td></tr></table></figure>
<h2 id="&#x76D1;&#x542C;&#x6765;&#x7535;&#x4E8B;&#x4EF6;"><a href="#&#x76D1;&#x542C;&#x6765;&#x7535;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x76D1;&#x542C;&#x6765;&#x7535;&#x4E8B;&#x4EF6;"></a>&#x76D1;&#x542C;&#x6765;&#x7535;&#x4E8B;&#x4EF6;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>:&#x62FF;&#x5230;&#x7535;&#x8BDD;&#x7BA1;&#x7406;&#x5668;</span><br><span class="line">  TelePMG = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);</span><br><span class="line"><span class="number">2</span>:&#x521B;&#x5EFA;&#x7535;&#x8BDD;&#x76D1;&#x542C;&#x5668;&#x7C7B;&#x7EE7;&#x627F;PhoneStateListener</span><br><span class="line">  <span class="class"><span class="keyword">class</span> <span class="title">MyPhoneStateListener</span> <span class="keyword">extends</span> <span class="title">PhoneStateListener</span></span>{</span><br><span class="line">        <span class="comment">//&#x91CD;&#x5199;&#x7535;&#x8BDD;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x7684;&#x65B9;&#x6CD5;</span></span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCallStateChanged</span><span class="params">(<span class="keyword">int</span> state, String incomingNumber)</span> </span>{</span><br><span class="line">            <span class="keyword">switch</span> (state){</span><br><span class="line">                <span class="keyword">case</span> TelephonyManager.CALL_STATE_IDLE:</span><br><span class="line">                    <span class="comment">//&#x7535;&#x8BDD;&#x7A7A;&#x95F2;&#x72B6;&#x6001;</span></span><br><span class="line">                    System.out.println(<span class="string">&quot;&#x7A7A;&#x95F2;&#x72B6;&#x6001;&quot;</span>);</span><br><span class="line">                    <span class="keyword">if</span>(mWindowManager!=<span class="keyword">null</span>&amp;&amp;toast_view!=<span class="keyword">null</span>){</span><br><span class="line">                        <span class="comment">//&#x6302;&#x65AD;&#x7535;&#x8BDD;&#x7684;&#x65F6;&#x5019;&#x79FB;&#x9664;&#x5410;&#x53F8;</span></span><br><span class="line">                        mWindowManager.removeView(toast_view);</span><br><span class="line">                    }</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> TelephonyManager.CALL_STATE_OFFHOOK:</span><br><span class="line">                    <span class="comment">//&#x5FD9;&#x788C;&#x72B6;&#x6001;&#xFF0C;&#x5C31;&#x662F;&#x5360;&#x7EBF;</span></span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> TelephonyManager.CALL_STATE_RINGING:</span><br><span class="line">                    <span class="comment">//&#x6765;&#x7535;&#x72B6;&#x6001;</span></span><br><span class="line">                    System.out.println(<span class="string">&quot;&#x6765;&#x7535;&#x4E86;&#x53F7;&#x7801;&#x662F;&quot;</span>+incomingNumber);</span><br><span class="line">                    <span class="comment">//&#x6765;&#x7535;&#x540E;&#x6253;&#x5370;&#x5410;&#x53F8;</span></span><br><span class="line">                    showToast(incomingNumber);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">            }</span><br><span class="line">            <span class="keyword">super</span>.onCallStateChanged(state, incomingNumber);</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line"><span class="number">3</span>:&#x521B;&#x5EFA;&#x7535;&#x8BDD;&#x76D1;&#x542C;&#x5668;&#x7684;&#x5BF9;&#x8C61;</span><br><span class="line">  myPhoneStateListener = <span class="keyword">new</span> MyPhoneStateListener();</span><br><span class="line"><span class="number">4</span>:&#x4F7F;&#x7528;&#x7535;&#x8BDD;&#x7BA1;&#x7406;&#x5668;&#x7684;listen&#x65B9;&#x6CD5;&#x7ED1;&#x5B9A;&#x76D1;&#x542C;&#x5668;</span><br><span class="line">  TelePMG.listen(myPhoneStateListener,PhoneStateListener.LISTEN_CALL_STATE);</span><br><span class="line"><span class="number">5</span>:&#x4F7F;&#x7528;&#x5B8C;&#x6BD5;&#x540E;&#x8BB0;&#x5F97;&#x7528;CLOSE&#x65B9;&#x6CD5;&#x5173;&#x95ED;</span><br></pre></td></tr></table></figure>
<h2 id="&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;"><a href="#&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;" class="headerlink" title="&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;"></a>&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>:&#x521B;&#x5EFA;&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;&#x7684;&#x7C7B;&#xFF08;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#x76D1;&#x542C;&#x7528;&#x6237;&#x624B;&#x52BF;&#x7684;&#x76D1;&#x542C;&#x5668;&#xFF09;</span><br><span class="line">  GestureDetector gestureDetector = <span class="keyword">new</span> GestureDetector(<span class="keyword">this</span>,SimpleOnGestureListener)</span><br><span class="line"><span class="number">2</span>:&#x5B9E;&#x73B0;&#x76D1;&#x542C;&#x5668;&#x7684;onFling&#x65B9;&#x6CD5;&#xFF08;&#x624B;&#x52BF;&#x8D77;&#x70B9;&#x53C2;&#x6570;&#xFF0C;&#x624B;&#x52BF;&#x79FB;&#x52A8;&#x5F53;&#x524D;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x6BCF;&#x79D2;x&#x8F74;&#x65B9;&#x5411;&#x79FB;&#x52A8;&#x7684;&#x50CF;&#x7D20;&#xFF0C;&#x6BCF;&#x79D2;y&#x8F74;&#x65B9;&#x5411;&#x79FB;&#x52A8;&#x7684;&#x50CF;&#x7D20;&#xFF09;</span><br><span class="line">  <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onFling</span><span class="params">(MotionEvent e1, MotionEvent e2, <span class="keyword">float</span> velocityX, <span class="keyword">float</span> velocityY)</span> </span>{</span><br><span class="line">                <span class="keyword">if</span> (e1.getX()-e2.getX()&gt;<span class="number">0</span>){</span><br><span class="line">                    <span class="comment">//&#x4E0B;&#x4E00;&#x9875;</span></span><br><span class="line">                    String phone = et_phone_number.getText().toString();</span><br><span class="line">                    <span class="keyword">if</span>(!TextUtils.isEmpty(phone)){</span><br><span class="line">                        Intent intent = <span class="keyword">new</span> Intent(Set_up3.<span class="keyword">this</span>, Set_up4.class);</span><br><span class="line">                        startActivity(intent);</span><br><span class="line">                        SpUtil.PutString(getApplicationContext(), FianlMath.CONTACT_MAN, phone);</span><br><span class="line">                        finish();</span><br><span class="line">                        overridePendingTransition(R.anim.next_anim_in,R.anim.next_anim_out);</span><br><span class="line">                    }<span class="keyword">else</span> {</span><br><span class="line">                        Toast.makeText(Set_up3.<span class="keyword">this</span>,<span class="string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x8054;&#x7CFB;&#x4EBA;&quot;</span>,Toast.LENGTH_SHORT).show();</span><br><span class="line">                    }</span><br><span class="line">                }<span class="keyword">else</span> <span class="keyword">if</span> (e1.getX()-e2.getX()&lt;<span class="number">0</span>){</span><br><span class="line">                    <span class="comment">//&#x4E0A;&#x4E00;&#x9875;</span></span><br><span class="line">                    Intent intent = <span class="keyword">new</span> Intent(Set_up3.<span class="keyword">this</span>, Set_up2.class);</span><br><span class="line">                    startActivity(intent);</span><br><span class="line">                    finish();</span><br><span class="line">                    overridePendingTransition(R.anim.up_anim_in,R.anim.up_anim_out);</span><br><span class="line">                }</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">super</span>.onFling(e1, e2, velocityX, velocityY);</span><br><span class="line">            }</span><br><span class="line"></span><br><span class="line">&#x91CD;&#x5199;ontouchevent&#x65B9;&#x6CD5;&#xFF08;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7528;&#x6765;&#x6355;&#x6349;&#x7528;&#x6237;&#x7684;&#x624B;&#x52BF;&#xFF09;</span><br><span class="line">      <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onTouchEvent</span><span class="params">(MotionEvent event)</span> </span>{</span><br><span class="line">        gestureDetector.onTouchEvent(event);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.onTouchEvent(event);</span><br><span class="line">    }</span><br></pre></td></tr></table></figure>
<h2 id="Android&#x4E2D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x521B;&#x5EFA;"><a href="#Android&#x4E2D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x521B;&#x5EFA;" class="headerlink" title="Android&#x4E2D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x521B;&#x5EFA;"></a>Android&#x4E2D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x521B;&#x5EFA;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>:&#x5199;&#x7C7B;&#x7EE7;&#x627F;SQLiteOpenHelper</span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BlackNamedb</span> <span class="keyword">extends</span> <span class="title">SQLiteOpenHelper</span></span>{</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">BlackNamedb</span><span class="params">(Context context)</span> </span>{</span><br><span class="line">        <span class="keyword">super</span>(context, <span class="string">&quot;blackname.db&quot;</span>, <span class="keyword">null</span>, <span class="number">1</span>);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(SQLiteDatabase sqLiteDatabase)</span> </span>{</span><br><span class="line">        <span class="comment">//&#x6267;&#x884C;SQL&#x8BED;&#x53E5;</span></span><br><span class="line">        sqLiteDatabase.execSQL(<span class="string">&quot;create table blackname&quot;</span> +</span><br><span class="line">                <span class="string">&quot;(_id integer primary key autoincrement,phone varchar(20),mode integer);&quot;</span>);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onUpgrade</span><span class="params">(SQLiteDatabase sqLiteDatabase, <span class="keyword">int</span> i, <span class="keyword">int</span> i2)</span> </span>{</span><br><span class="line"></span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"><span class="number">2</span>&#xFF1A;&#x91CD;&#x65B0;&#x5199;&#x7C7B;&#x79C1;&#x6709;&#x5316;&#x6784;&#x9020;&#x65B9;&#x6CD5;</span><br><span class="line"><span class="number">3</span>&#xFF1A;&#x7533;&#x660E;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x7684;&#x5F53;&#x524D;&#x7C7B;&#x5BF9;&#x8C61;</span><br><span class="line"><span class="number">3</span>&#xFF1A;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x5982;&#x679C;&#x5F53;&#x524D;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x4E3A;&#x7A7A;&#x5219;&#x8981;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5BF9;&#x8C61;</span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BlacknameJDBC</span> </span>{</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> BlackNamedb blackNamedb;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//1:&#x79C1;&#x6709;&#x5316;&#x6784;&#x9020;&#x65B9;&#x6CD5;</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="title">BlacknameJDBC</span><span class="params">(Context context)</span> </span>{</span><br><span class="line">        blackNamedb = <span class="keyword">new</span> BlackNamedb(context);</span><br><span class="line">    }</span><br><span class="line">    <span class="comment">//2:&#x7533;&#x660E;&#x5F53;&#x524D;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x3002;&#x5FC5;&#x987B;&#x662F;&#x9759;&#x6001;&#x7684;</span></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> BlacknameJDBC blacknameJDBC = <span class="keyword">null</span>;</span><br><span class="line">    <span class="comment">//3:&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x65B9;&#x6CD5;&#x5982;&#x679C;&#x5F53;&#x524D;&#x7C7B;&#x7684;&#x5BF9;&#x8C61;&#x4E3A;&#x7A7A;&#x5219;&#x8981;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x5BF9;&#x8C61;</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> BlacknameJDBC <span class="title">getInstance</span><span class="params">(Context context)</span></span>{</span><br><span class="line">        <span class="keyword">if</span> (blacknameJDBC==<span class="keyword">null</span>){</span><br><span class="line">            blacknameJDBC = <span class="keyword">new</span> BlacknameJDBC(context);</span><br><span class="line">            <span class="keyword">return</span> blacknameJDBC;</span><br><span class="line">        }<span class="keyword">else</span> {</span><br><span class="line">            <span class="keyword">return</span> blacknameJDBC;</span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line"><span class="number">4</span>&#xFF1A;&#x63D0;&#x4F9B;&#x589E;&#x5220;&#x6539;&#x67E5;&#x7B49;&#x64CD;&#x4F5C;</span><br><span class="line">     <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> phone &#x62E6;&#x622A;&#x7684;&#x7535;&#x8BDD;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> mode &#x62E6;&#x622A;&#x7684;&#x7C7B;&#x578B; 1&#x662F;&#x77ED;&#x4FE1;  2&#x662F;&#x7535;&#x8BDD;  3&#x662F;&#x6240;&#x6709;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">insert</span><span class="params">(String phone , String mode)</span></span>{</span><br><span class="line">        <span class="comment">//&#x5F00;&#x542F;&#x6570;&#x636E;&#x5E93;&#x505A;&#x5199;&#x5165;&#x64CD;&#x4F5C;</span></span><br><span class="line"></span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        <span class="comment">//&#x51C6;&#x5907;ContentValues &#x5C01;&#x88C5;</span></span><br><span class="line">        ContentValues values = <span class="keyword">new</span> ContentValues();</span><br><span class="line">        values.put(<span class="string">&quot;phone&quot;</span>,phone);</span><br><span class="line">        values.put(<span class="string">&quot;mode&quot;</span>,mode);</span><br><span class="line">        <span class="comment">//&#x8FDB;&#x884C;&#x5199;&#x5165;&#x64CD;&#x4F5C; &#x65B9;&#x6CD5;&#x63A5;&#x6536;&#x53C2;&#x6570;&#xFF08;&#x8868;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x6CA1;&#x6709;&#x7ED9;&#x503C;&#x65F6;&#xFF0C;&#x5C06;null&#x63D2;&#x5165;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x5185;&#x5BB9; ContentValues &#x7528;&#x8FD9;&#x4E2A;&#x5C01;&#x88C5;&#xFF09;&#xFF1B;</span></span><br><span class="line">        writableDatabase.insert(<span class="string">&quot;blackname&quot;</span>,<span class="keyword">null</span>,values);</span><br><span class="line"></span><br><span class="line">        blackNamedb.close();</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> phone  &#x60F3;&#x8981;&#x5220;&#x9664;&#x7684;&#x7535;&#x8BDD;&#x53F7;&#x7801;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">delect</span><span class="params">(String phone)</span></span>{</span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        <span class="comment">//&#x8FDB;&#x884C;&#x5220;&#x9664;&#x64CD;&#x4F5C;&#xFF08;&#x8868;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x8981;&#x5220;&#x9664;&#x7684;&#x5B57;&#x6BB5;&#x540D;&#x79F0;&#xFF0C;&#x8981;&#x5220;&#x9664;&#x7684;&#x5B57;&#x6BB5;&#x503C;,&#x8981;&#x4F7F;&#x7528;String&#x7C7B;&#x578B;&#x7684;&#x6570;&#x7EC4;&#xFF09;</span></span><br><span class="line">        writableDatabase.delete(<span class="string">&quot;blackname&quot;</span>,<span class="string">&quot;phone=?&quot;</span>,<span class="keyword">new</span> String[]{phone});</span><br><span class="line">        writableDatabase.close();</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     *  &#x6839;&#x636E;&#x7535;&#x8BDD;&#x53F7;&#x7801;&#x53BB;&#x66F4;&#x65B0;&#x62E6;&#x622A;&#x6A21;&#x5F0F;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> phone &#x8981;&#x66F4;&#x65B0;&#x7684;&#x7535;&#x8BDD;</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> mode &#x8981;&#x66F4;&#x65B0;&#x4E3A;&#x7684;&#x6A21;&#x5F0F;(1:&#x77ED;&#x4FE1;    2:&#x7535;&#x8BDD;    3:&#x62E6;&#x622A;&#x6240;&#x6709;(&#x77ED;&#x4FE1;+&#x7535;&#x8BDD;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">updata</span><span class="params">(String phone,String mode)</span></span>{</span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        <span class="comment">//&#x51C6;&#x5907;&#x6570;&#x636E;</span></span><br><span class="line">        ContentValues values = <span class="keyword">new</span> ContentValues();</span><br><span class="line">        values.put(<span class="string">&quot;mode&quot;</span>,mode);</span><br><span class="line">        <span class="comment">//  ava.lang.String table, android.content.ContentValues values, java.lang.String whereClause, java.lang.String[] whereArgs</span></span><br><span class="line">        <span class="comment">//&#x8FDB;&#x884C;&#x66F4;&#x65B0;&#x64CD;&#x4F5C;(&#x8868;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x8981;&#x66F4;&#x65B0;&#x7684;&#x503C;&#xFF0C;&#x8981;&#x66F4;&#x65B0;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x4F9D;&#x636E;&#x4EC0;&#x4E48;&#x5B57;&#x6BB5;&#x66F4;&#x65B0;)</span></span><br><span class="line">        writableDatabase.update(<span class="string">&quot;blackname&quot;</span>,values,<span class="string">&quot;mode=?&quot;</span>,<span class="keyword">new</span> String[]{phone});</span><br><span class="line">        writableDatabase.close();</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * &#x8FD4;&#x56DE;&#x7684;&#x5C31;&#x662F;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x53F7;&#x7801;&#x4EE5;&#x53CA;&#x7C7B;&#x578B;</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;Blacknamebin&gt; <span class="title">FindAll</span><span class="params">()</span></span>{</span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        <span class="comment">//&#x67E5;&#x8BE2;(&#x8868;&#x540D;&#xFF0C;&#x67E5;&#x8BE2;&#x7684;&#x5B57;&#x6BB5;,&#x67E5;&#x8BE2;&#x7684;&#x6761;&#x4EF6;&#xFF0C;&#x67E5;&#x8BE2;&#x7684;&#x6761;&#x4EF6;&#xFF0C;&#x67E5;&#x8BE2;&#x7684;&#x6761;&#x4EF6;&#xFF0C;&#x67E5;&#x8BE2;&#x7684;&#x6761;&#x4EF6;&#xFF0C;  &#x67E5;&#x8BE2;&#x51FA;&#x6765;&#x6392;&#x5E8F;&#x7684;&#x65B9;&#x6CD5; &#x9ED8;&#x8BA4;&#x4E3A;&#x6B63;&#x5E8F;&#xFF0C;desc&#x4E3A;&#x5012;&#x53D9;)</span></span><br><span class="line">        <span class="comment">//&#x62FF;&#x5230;&#x6E38;&#x6807;</span></span><br><span class="line">        Cursor query = writableDatabase.query(<span class="string">&quot;blackname&quot;</span>, <span class="keyword">new</span> String[]{<span class="string">&quot;phone&quot;</span>, <span class="string">&quot;mode&quot;</span>}, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="keyword">null</span>, <span class="string">&quot;_id desc&quot;</span>);</span><br><span class="line">        <span class="comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x96C6;&#x5408;</span></span><br><span class="line">        List&lt;Blacknamebin&gt; blackname = <span class="keyword">new</span> ArrayList&lt;Blacknamebin&gt;();</span><br><span class="line">        <span class="keyword">while</span> (query.moveToNext()){</span><br><span class="line">            <span class="comment">//&#x751F;&#x6210;&#x4E00;&#x4E2A;BIN&#x7C7B;&#x653E;&#x5E38;&#x7528;&#x5B57;&#x6BB5;</span></span><br><span class="line">            Blacknamebin blacknamebin = <span class="keyword">new</span> Blacknamebin();</span><br><span class="line">            blacknamebin.phone = query.getString(<span class="number">0</span>);</span><br><span class="line">            blacknamebin.mode = query.getString(<span class="number">1</span>);</span><br><span class="line">            System.out.println(<span class="string">&quot;blacknamebin.phone&quot;</span>+query.getString(<span class="number">0</span>)+<span class="string">&quot;````````````blacknamebin.mode&quot;</span>+query.getString(<span class="number">1</span>));</span><br><span class="line">            blackname.add(blacknamebin);</span><br><span class="line">        }</span><br><span class="line">        query.close();</span><br><span class="line">        writableDatabase.close();</span><br><span class="line">        <span class="keyword">return</span> blackname;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;Blacknamebin&gt; <span class="title">FindOther</span><span class="params">(<span class="keyword">int</span> index)</span></span>{</span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        Cursor query = writableDatabase.rawQuery(<span class="string">&quot;select phone,mode from blackname order by _id desc limit ?,10;&quot;</span>, <span class="keyword">new</span> String[]{index+<span class="string">&quot;&quot;</span>});</span><br><span class="line">        List&lt;Blacknamebin&gt; blackname = <span class="keyword">new</span> ArrayList&lt;Blacknamebin&gt;();</span><br><span class="line">        <span class="keyword">while</span> (query.moveToNext()){</span><br><span class="line">            <span class="comment">//&#x751F;&#x6210;&#x4E00;&#x4E2A;BIN&#x7C7B;&#x653E;&#x5E38;&#x7528;&#x5B57;&#x6BB5;</span></span><br><span class="line">            Blacknamebin blacknamebin = <span class="keyword">new</span> Blacknamebin();</span><br><span class="line">            blacknamebin.phone = query.getString(<span class="number">0</span>);</span><br><span class="line">            blacknamebin.mode = query.getString(<span class="number">1</span>);</span><br><span class="line">            System.out.println(<span class="string">&quot;blacknamebin.phone&quot;</span>+query.getString(<span class="number">0</span>)+<span class="string">&quot;````````````blacknamebin.mode&quot;</span>+query.getString(<span class="number">1</span>));</span><br><span class="line">            blackname.add(blacknamebin);</span><br><span class="line">        }</span><br><span class="line">        query.close();</span><br><span class="line">        writableDatabase.close();</span><br><span class="line">        <span class="keyword">return</span> blackname;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getCount</span><span class="params">()</span></span>{</span><br><span class="line">        SQLiteDatabase writableDatabase = blackNamedb.getWritableDatabase();</span><br><span class="line">        Cursor cursor = writableDatabase.rawQuery(<span class="string">&quot;select count(*) from blackname;&quot;</span>, <span class="keyword">null</span>);</span><br><span class="line">        <span class="keyword">int</span> count =<span class="number">0</span> ;</span><br><span class="line">        <span class="keyword">if</span> (cursor.moveToNext()){</span><br><span class="line">            count = cursor.getInt(<span class="number">0</span>);</span><br><span class="line">        }</span><br><span class="line">        cursor.close();</span><br><span class="line">        writableDatabase.close();</span><br><span class="line">        <span class="keyword">return</span> count;</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Anderoid基础/" rel="tag"># Anderoid基础</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/29/前端JavaScript（二）/" rel="next" title="前端JavaScript（二）">
                <i class="fa fa-chevron-left"></i> 前端JavaScript（二）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/30/Android基础（二）/" rel="prev" title="Android基础（二）">
                Android基础（二） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义对话框"><span class="nav-number">1.</span> <span class="nav-text">自定义对话框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ListView的优化"><span class="nav-number">2.</span> <span class="nav-text">ListView的优化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ConvertView的复用"><span class="nav-number">2.1.</span> <span class="nav-text">ConvertView的复用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#findViewById的复用-ViewHolder的使用"><span class="nav-number">2.2.</span> <span class="nav-text">findViewById的复用 ViewHolder的使用</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#将流转换为字符串"><span class="nav-number">3.</span> <span class="nav-text">将流转换为字符串</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#服务端JSON写法"><span class="nav-number">4.</span> <span class="nav-text">服务端JSON写法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON解析（不适用Gson）"><span class="nav-number">5.</span> <span class="nav-text">JSON解析（不适用Gson）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用开源框架Xutils下载"><span class="nav-number">6.</span> <span class="nav-text">使用开源框架Xutils下载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#监听来电事件"><span class="nav-number">7.</span> <span class="nav-text">监听来电事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#监听用户手势"><span class="nav-number">8.</span> <span class="nav-text">监听用户手势</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Android中数据库的创建"><span class="nav-number">9.</span> <span class="nav-text">Android中数据库的创建</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
